{include file=member.header.html}
<script type="text/javascript">
function jsApiCall(){
	WeixinJSBridge.invoke(
				'editAddress',
				{$jsApiAddrParameters},
				function(res){
					//alert(res.addressDetailInfo);
					// for (var a in res)
				    // {
				        // alert(a);
				    // }
					$('#consignee').val(res.userName);
					$('#region_name_dis').html(res.proviceFirstStageName + " " + res.addressCitySecondStageName + " " + res.addressCountiesThirdStageName);
					$('#region_name').val(res.proviceFirstStageName + " " + res.addressCitySecondStageName + " " + res.addressCountiesThirdStageName);
					$('#address').val(res.addressDetailInfo);
					$('#phone_mob').val(res.telNumber);
					$('#zipcode').val(res.addressPostalCode);
				}
			);
}
function getWxAddr()
{
	if (typeof WeixinJSBridge == "undefined"){
	    if( document.addEventListener ){
	        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
	    }else if (document.attachEvent){
	        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
	        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
	    }
	}else{
	    jsApiCall();
	    
	}
}
$(function(){
    regionInit("region");
    getWxAddr();
    $('#region_id').val('2');
})

function submitData()
{
	var consignee = $('#consignee').val();
	var region_id = $('#region_id').val();
	var region_name= $('#region_name').val();
	var address   = $('#address').val();
	var phone_mob = $('#phone_mob').val();
	var phone_tel = $('#phone_tel').val();
	var zipcode   = $('#zipcode').val();
	var ret_url = '{$smarty.get.ret_url}';
	if(consignee == "")
	{
		errormsg('{$lang.consignee_required}');
	}
	else
	{
		if(region_id == "")
		{
			errormsg('{$lang.region_required}');
		}
		else
		{
			if(region_id < 1)
			{
				errormsg('{$lang.region_required}');
			}
			else
			{
				if(address == "")
				{
					errormsg('{$lang.address_required}');
				}
				else
				{
					if(phone_tel == "" && phone_mob == "")
					{
						errormsg('{$lang.phone_required}');
					}
					else
					{
						var url = REAL_SITE_URL+"/index.php?app=my_address&act={$act}&addr_id={$address.addr_id}";
						$.post(url,{consignee:consignee,address:address,region_id:region_id,region_name:region_name,phone_mob:phone_mob,phone_tel:phone_tel,zipcode:zipcode},function(data){
							if(data == true){
									<!--{if $act eq 'edit'}-->
									msg("{$lang.edit_address_success}");
									<!--{else}-->
									msg("{$lang.add_address_success}");
									<!--{/if}-->
									setTimeout(function(){
											window.location.href=ret_url?ret_url:"{url app=my_address}";
									},1500);
							}  
						},"json");						
					}
				}
			}
		}
	}
}
</script>
<div id="page-my-address">
	<div class="page-body add-address">
		<ul class="padding10">
				<li><input type="text"  class="input" name="consignee" id="consignee" value="{$address.consignee|escape}" placeholder="{$lang.consignee_desc}"/></li>
				<li class="mb10 edit-region">
						<div id="region">
							<input type="hidden" name="region_id" value="{$address.region_id}" id="region_id" class="mls_id" />
							<input type="hidden" name="region_name" id="region_name" value="{$address.region_name|escape}" class="mls_names" />
							<span id="region_name_dis">{$address.region_name|escape}</span>
							<input type="button" value="编辑区域" class="edit_region" />
							<select style="display:none; ">
							  <option>{$lang.select_pls}</option>
							  {html_options options=$regions}
							</select>
							
						  </div>
				</li>
				<li>
            <input type="text"   class="input" id="address" name="address" value="{$address.address|escape}" placeholder="{$lang.address_desc}"/>
        </li>
        <li>
            <input type="text"  class="input" placeholder="{$lang.zipcode}" id="zipcode" name="zipcode" value="{$address.zipcode|escape}" />
        </li>
        <li>
            <input type="text"   class="input" id="phone_tel" name="phone_tel" value="{$address.phone_tel}" placeholder="{$lang.phone_format}"/>
        </li>
        <li>
            <input type="text"   class="input" placeholder="{$lang.phone_mob}" id="phone_mob" name="phone_mob" value="{$address.phone_mob}"/>
        </li>
		<div class="btn-box">
		<input type="button" onclick="submitData();" value="<!--{if $address.addr_id}-->{$lang.edit_address}<!--{else}-->{$lang.add_address}<!--{/if}-->" />
		</div>
		</ul>
	</div>
</div>
